package com.neuedu.hisadmin.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import java.util.List;
import com.neuedu.hisadmin.entity.Rule;
import com.neuedu.hisadmin.dto.RuleDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface RuleMapper extends BaseMapper<Rule> {

    // 关联查询：rule + department + user


    @Select("SELECT " +
            "r.ID AS id, " +                // 与 RuleVO.id 匹配
            "r.RuleName AS ruleName, " +    // 与 RuleVO.ruleName 匹配
            "d.DeptName AS deptName, " +    // 与 RuleVO.deptName 匹配
            "u.RealName AS realName, " +    // 与 RuleVO.realName 匹配
            "r.Week AS week, " +             // 与 RuleVO.week 匹配
            "r.DelMArk AS delMark, " +      // 与 RuleVO.delMark 匹配
            "r.num AS num " +                // 与 RuleVO.num 匹配
            "FROM rule r " +
            "INNER JOIN department d ON r.deptID = d.id " +
            "INNER JOIN user u ON r.userID = u.id " +
            "WHERE r.DelMark = 1")
    List<RuleDTO> getRuleWithRelations();

    // 带条件查询（同样添加 AS 关键字）
    @Select("SELECT " +
            "r.ID AS id, " +
            "r.RuleName AS ruleName, " +
            "d.DeptName AS deptName, " +
            "u.RealName AS realName, " +
            "r.Week AS week, " +
            "r.DelMark AS delMark, " +
            "r.num AS num " +
            "FROM rule r " +
            "INNER JOIN department d ON r.deptID = d.id " +
            "INNER JOIN user u ON r.userID = u.id " +
            "WHERE r.DelMark = 1 " +
            "AND d.DeptName LIKE CONCAT('%', #{deptName}, '%') " +
            "AND u.RealName LIKE CONCAT('%', #{doctorName}, '%') " +
            "AND r.RuleName LIKE CONCAT('%', #{ruleName}, '%')")
    List<RuleDTO> getRuleWithRelationsByCondition(
            @Param("deptName") String deptName,
            @Param("doctorName") String doctorName,
            @Param("ruleName") String ruleName
    );
}